package com.sbl.bajw.pc.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sbl.bajw.common.web.JsonResultUtil;
import com.sbl.bajw.common.web.RequestUnit;
import com.sbl.bajw.pc.service.AppLogService;
import com.sbl.bajw.util.HttpUtil;
import com.sbl.bajw.util.LogUtil;

@Controller
@RequestMapping("/GpsLocation")
public class GpsLocationAction {
	
	@Resource
	private AppLogService service;
	
	static Logger log;
	
	static{
		log = LogUtil.getLogger("applog");
	}
	
	@RequestMapping(value = "/getAddress")
	public @ResponseBody String getAddress(HttpServletRequest request, HttpServletResponse response) throws Exception{
		String apkKey = "X1j8IIXvLlbWg1eP3K9jdmww";
		String lon = RequestUnit.getString("lon");
		String lat = RequestUnit.getString("lat");
		if(lon==null||lon.equals("") || lat == null || lat.equals("")){
			return JsonResultUtil.Error("经纬度非法");
		}
		String url = "http://api.map.baidu.com/geocoder/v2/?ak="+apkKey+"&location="+lat+","+lon+"&output=json&pois=0";
		
		String json =HttpUtil.getData(url, null, "UTF-8");
		
		return JsonResultUtil.Success(json);
	}
}
